package com.mxpio.erp.mes.controller;

import com.mxpio.erp.common.mes.entity.*;
import com.mxpio.erp.common.mes.service.*;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Order;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author : wpp
 * @Datetime : 2023/9/1 11:30
 * @Desc :
 * @Modor :  Modifytime:
 * @modDesc :
 */
@Tag(name = "SpiViewController", description = "spi相关视图接口")
@RestController
@RequestMapping("/erp/mes/spi/")
public class SpiViewController {

    @Autowired
    private VSpiLineNumberService vSpiLineNumberService;
    @Autowired
    private VSpiLineSumByDayService vSpiLineSumByDayService;

    @Autowired
    private VSpiDaySumService vSpiDaySumService;
    @Autowired
    private VSpiDayTwoHoursSumService vSpiDayTwoHoursSumService;
    @Autowired
    private VSpiModelDaySumService vSpiModelDaySumService;
    @Autowired
    private VSpiModelNgDaySumService vSpiModelNgDaySumService;
    @Autowired
    private VSpiDayPpmService vSpiDayPpmService;
    @GetMapping("linenumber/list")
    @Operation(summary = "spi线别（下拉框数据源）", description = "spi线别（下拉框数据源）", method = "GET")
    public Result<List<VSpiLineNumber>> linenumberList(Criteria criteria)  {
        List<VSpiLineNumber> list = vSpiLineNumberService.list(criteria);
        return Result.OK(list);
    }
    @GetMapping("linesumbyday/list")
    @Operation(summary = "spi检测按天汇总（产量+合格率）", description = "spi检测按天汇总（产量+合格率）", method = "GET")
    public Result<VSpiLineSumByDay> spiLineSumByDayList(Criteria criteria)  {
        List<VSpiLineSumByDay> list = vSpiLineSumByDayService.list(criteria);
        if (list.size()>0){
            return Result.OK(list.get(0));
        }
        return Result.OK();
    }
    @GetMapping("spidaysum/list")
    @Operation(summary = "spi按天检测量（按小板汇总）", description = "spi按天检测量（按小板汇总）", method = "GET")
    public Result<VSpiDaySum> spiDaySumList(Criteria criteria)  {
        List<VSpiDaySum> list = vSpiDaySumService.list(criteria);
        if (list.size()>0){
            return Result.OK(list.get(0));
        }
        return Result.OK();
    }
    @GetMapping("spimodeldaysum/list")
    @Operation(summary = "spi设备按天检测量（按小板汇总）", description = "spi设备按天检测量（按小板汇总）", method = "GET")
    public Result<List<VSpiModelDaySum>> spiModelDaySumList(Criteria criteria)  {
        List<VSpiModelDaySum> list = vSpiModelDaySumService.list(criteria);
        return Result.OK(list);
    }
    @GetMapping("spimodelngdaysum/list")
    @Operation(summary = "spi设备按天NG检测量（按小板汇总）", description = "spi设备按天NG检测量（按小板汇总）", method = "GET")
    public Result<List<VSpiModelNgDaySum>> spiModelNgDaySumList(Criteria criteria)  {
        Pageable page = PageRequest.of(0, 10);//取10条
        if (criteria==null){
            criteria = Criteria.create();
        }
        criteria.addOrder(new Order("ngSum",true));
        Page<VSpiModelNgDaySum> vSpiModelNgDaySums = vSpiModelNgDaySumService.listPage(page, criteria);
        return Result.OK(vSpiModelNgDaySums.getContent());
    }
    @GetMapping("spidaytwohourssum/list")
    @Operation(summary = "spi按天两小时合计检测量（按小板汇总）", description = "spi按天两小时合计检测量（按小板汇总）", method = "GET")
    public Result<List<VSpiDayTwoHoursSum>> spiDayTwoHoursSumList(Criteria criteria)  {
        List<VSpiDayTwoHoursSum> list = vSpiDayTwoHoursSumService.list(criteria);
        return Result.OK(list);
    }

    @GetMapping("dayppm/list")
    @Operation(summary = "spi按天ppm趋势", description = "spi按天ppm趋势", method = "GET")
    public Result<VSpiDayPpm> aoippmList(Criteria criteria)  {
        List<VSpiDayPpm> list = vSpiDayPpmService.list(criteria);
        if (list.size()>0){
            return Result.OK(list.get(0));
        }
        return Result.OK();
    }
}
